<%@ page contentType="text/html;charset=UTF-8"%>
<%@ page isELIgnored="false"%>
<%@ page import="org.apache.shiro.authc.ExcessiveAttemptsException"%>
<%@ page import="org.apache.shiro.authc.IncorrectCredentialsException"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%  response.setHeader("Set-Cookie", "name=xsbd; HttpOnly");%>
<%  response.setHeader("Set-Cookie", "name=ssiid; Secure");%>
<!DOCTYPE html>
<head>
<title>人员合法性管理系统</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Cache-Control" content="no-cache" />
<link href="css/login.css" rel="stylesheet" />
<link href="css/style.css" rel="stylesheet" type="text/css" />
<script src="js/jquery.min.js"></script>
<script src="js/DateConvertUtil.js"></script>
<script src="js/jquery.easyui.min.js"></script>
<link href="js/themes/bootstrap/easyui.css" rel="stylesheet"/>
<link href="js/themes/icon.css" rel="stylesheet" />
<script src="js/common.js"></script>
<!-- <script type="text/javascript" charset="utf-8" src="js/validata.js"></script> -->
<script type="text/javascript" language="javascript">
	
	function sub() {
		/* var code = $("#code").val();
		if (!code) {
			$.messager.alert("提示","请输入验证码");
			return;
		}
		var flag = true;
		$.ajax({
			type : "get",
			url : "adminValiCode.do",
			data : {"code": code},
			async : false,
			success : function(data) {
				if(data.isError){
					$.messager.alert("提示","验证码错误,请重新输入");
					flag = false;
					return;
				}
			}
		});
		if(!flag) {
			return;
		} */
		var a = document.getElementById("username").value;
		var b = document.getElementById("userpasswd").value;
		if (a == '') {
			$.messager.alert("提示","用户名不能为空");
			return;
		}
		if (a.length > 20) {
			$.messager.alert("提示","用户名过长,请输入小于20位字符");
			return;
		}
		if (b == '') {
			$.messager.alert("提示","密码不能为空");
			return;
		}
		if (b.length > 20) {
			$.messager.alert("提示","密码过长,请输入小于20位字符");
			return;
		}
		
		//var regex = /(?!^[0-9]+$)(?!^[a-zA-Z]+$)[a-zA-Z0-9]{6,35}/;
		var regex = /^(?![^a-zA-Z]+$)(?!\D+$)[0-9a-zA-Z]{6,35}$/;
		var ret = regex.test(b);
// 		if(!ret){
// 			$.messager.alert('安全提示', "密码安全系数较低，请登录成功后重新设置密码", '安全提示',function(){});
//      	}
		document.getElementById("myform").submit();
	}
	$(document).ready(function() {
		$('#userpasswd')[0].onkeypress = function(event) {
			var e = event || window.event, $tip = $('#capslock'), kc = e.keyCode
					|| e.which, // 按键的keyCode
			isShift = e.shiftKey || (kc == 16) || false; // shift键是否按住
			if (((kc >= 65 && kc <= 90) && !isShift)
					|| ((kc >= 97 && kc <= 122) && isShift)) {
				$tip.show();
			} else {
				$tip.hide();
			}
		};
		
	});
	
	//获取验证码
	function getCode() {
		var username = document.getElementById("username").value;
		if (username == '') {
			$.messager.alert("提示","用户名不能为空");
			return;
		}
		$.ajax({
			type : "get",
			url : "adminGetCode.do",
			data : {"username": username},
			async : false,
			success : function(data) {
				//alert(JSON.stringify(data));
			}
		});
		$("#getCodeBtn").removeAttr("onclick");
		downTime();
	}

	function downTime() {
		var at = 60;
		var MyTime = setInterval(function() {
			if (at > 0) {
				at--;
				$("#getCodeBtn").text(at + "S后获取");
			} else if (at == 0) {
				$("#getCodeBtn").text("获取验证码").attr("onclick", "getCode()");
				clearInterval(MyTime);
			}
		}, 1000);
	}
</script>
<style type="text/css">
.noBut {
    background-color: #CCCCCC;
}
</style>
</head>
<body class="login_wp">
	<div class="login_wp">
		<div class="bj_hover"></div>
		<div class="loginPage">
			<div class="loginBox rmtS">
				<form name="myform" id="myform" action="submitLogin.do" method="post">
<!-- 					<div class="loginTitle"></div>
 -->					<div class="loginList">
						<div class="loginListRow">
							<input placeholder="用户名" id="username" name="username"
								value="${username}" class="inputText inputBlock focus"
								type="text" validType="loginName">
						</div>
						<div class="loginListRow">
							<div id="capslock" class="zimutishi" style="display: none">
								<i></i>大写键盘已开启，请注意大小写!
							</div>
							<input placeholder="密码" name="userpasswd" id="userpasswd"
								onpaste='return false' oncopy='return false'
								class="inputText inputBlock" type="password" class="passwd"
								validType="capsLockTip" autocomplete="off">
						</div>
						<!-- <div class="loginListRow">
							<input placeholder="输入发送至绑定手机的验证码" name="code" id="code"
								class="inputText inputBlock" style="width:65%; height: 38px;" >
								<a href="#" id="getCodeBtn" onclick="getCode()" 
									class="easyui-linkbutton" >获取验证码</a>
						</div> -->
						<div>
							<c:choose>
								<c:when test="${shiroLoginFailure eq 'unknownUserError'}">
									<div class="error-msg prepend-top">用户名或未知用户</div>
								</c:when>
								<c:when test="${shiroLoginFailure eq 'userOrPasswdError'}">
									<div class="error-msg prepend-top">用户名或密码错误</div>
								</c:when>
							</c:choose>
						</div>
						<input style="display:none;" type="submit">

						<div class="pt20">
							<a href="javascript:void(0);" onclick="sub()" role="submitBtn"
								class="btn block blue">登 录</a>
						</div>

					</div>
			  </form>
			</div>
			<div class="footer">
				<p>人员合法性管理系统</p>
			</div>
		</div>
	</div>
</body>
</html>